def pal(n):
    n = str(n)
    re_num = n[::-1]
    return re_num == n
def Primer(n):
    if n <= 1:
        return False
    for i in range(2,n):
        if n % i == 0:
            return False
    return True
def Emirp(n):
    re_num = int(str(n)[::-1])
    if not pal(re_num) and Primer(re_num) and Primer(n):
        return True
    else:
        return False
n = int(input())
for i in range(n+1):
    if Emirp(i):
        print(i)